home *** CD-ROM | disk | FTP | other *** search
/ SGI Freeware 1999 August / SGI Freeware 1999 August.iso / dist / fw_perl.idb / usr / freeware / catman / p_man / cat3 / FileHandle.Z / FileHandle
Encoding:
Text File  |  1998-10-28  |  7.0 KB  |  265 lines

  1.  
  2.  
  3.  
  4.      FFFFiiiilllleeeeHHHHaaaannnnddddlllleeee((((3333))))   22223333////JJJJuuuullll////99998888 ((((ppppeeeerrrrllll 5555....000000005555,,,, ppppaaaattttcccchhhh 00002222))))     FFFFiiiilllleeeeHHHHaaaannnnddddlllleeee((((3333))))
  5.  
  6.  
  7.  
  8.      NNNNAAAAMMMMEEEE
  9.       FileHandle - supply object methods for filehandles
  10.  
  11.      SSSSYYYYNNNNOOOOPPPPSSSSIIIISSSS
  12.           use FileHandle;
  13.  
  14.           $fh = new    FileHandle;
  15.           if ($fh->open("< file")) {
  16.           print    <$fh>;
  17.           $fh->close;
  18.           }
  19.  
  20.           $fh = new    FileHandle "> FOO";
  21.           if (defined $fh) {
  22.           print    $fh "bar\n";
  23.           $fh->close;
  24.           }
  25.  
  26.           $fh = new    FileHandle "file", "r";
  27.           if (defined $fh) {
  28.           print    <$fh>;
  29.           undef    $fh;       # automatically closes the file
  30.           }
  31.  
  32.           $fh = new    FileHandle "file", O_WRONLY|O_APPEND;
  33.           if (defined $fh) {
  34.           print    $fh "corge\n";
  35.           undef    $fh;       # automatically closes the file
  36.           }
  37.  
  38.           $pos = $fh->getpos;
  39.           $fh->setpos($pos);
  40.  
  41.           $fh->setvbuf($buffer_var,    _IOLBF,    1024);
  42.  
  43.           ($readfh,    $writefh) = FileHandle::pipe;
  44.  
  45.           autoflush    STDOUT 1;
  46.  
  47.  
  48.      DDDDEEEESSSSCCCCRRRRIIIIPPPPTTTTIIIIOOOONNNN
  49.       NOTE:    This class is now a front-end to the IO::* classes.
  50.  
  51.       FileHandle::new creates a FileHandle,    which is a reference
  52.       to a newly created symbol (see the Symbol package).  If it
  53.       receives any parameters, they    are passed to
  54.       FileHandle::open; if the open    fails, the FileHandle object
  55.       is destroyed.     Otherwise, it is returned to the caller.
  56.  
  57.       FileHandle::new_from_fd creates a FileHandle like new    does.
  58.       It requires two parameters, which are    passed to
  59.       FileHandle::fdopen; if the fdopen fails, the FileHandle
  60.  
  61.  
  62.  
  63.      Page 1                        (printed 10/23/98)
  64.  
  65.  
  66.  
  67.  
  68.  
  69.  
  70.      FFFFiiiilllleeeeHHHHaaaannnnddddlllleeee((((3333))))   22223333////JJJJuuuullll////99998888 ((((ppppeeeerrrrllll 5555....000000005555,,,, ppppaaaattttcccchhhh 00002222))))     FFFFiiiilllleeeeHHHHaaaannnnddddlllleeee((((3333))))
  71.  
  72.  
  73.  
  74.       object is destroyed.    Otherwise, it is returned to the
  75.       caller.
  76.  
  77.       FileHandle::open accepts one parameter or two.  With one
  78.       parameter, it    is just    a front    end for    the built-in open
  79.       function.  With two parameters, the first parameter is a
  80.       filename that    may include whitespace or other    special
  81.       characters, and the second parameter is the open mode,
  82.       optionally followed by a file    permission value.
  83.  
  84.       If FileHandle::open receives a Perl mode string (">",    "+<",
  85.       etc.)     or a POSIX _f_o_p_e_n() mode string    ("w", "r+", etc.), it
  86.       uses the basic Perl open operator.
  87.  
  88.       If FileHandle::open is given a numeric mode, it passes that
  89.       mode and the optional    permissions value to the Perl sysopen
  90.       operator.  For convenience, FileHandle::import tries to
  91.       import the O_XXX constants from the Fcntl module.  If
  92.       dynamic loading is not available, this may fail, but the
  93.       rest of FileHandle will still    work.
  94.  
  95.       FileHandle::fdopen is    like open except that its first
  96.       parameter is not a filename but rather a file    handle name, a
  97.       FileHandle object, or    a file descriptor number.
  98.  
  99.       If the C functions _f_g_e_t_p_o_s() and _f_s_e_t_p_o_s() are available,
  100.       then FileHandle::getpos returns an opaque value that
  101.       represents the current position of the FileHandle, and
  102.       FileHandle::setpos uses that value to    return to a previously
  103.       visited position.
  104.  
  105.       If the C function _s_e_t_v_b_u_f() is available, then
  106.       FileHandle::setvbuf sets the buffering policy    for the
  107.       FileHandle.  The calling sequence for    the Perl function is
  108.       the same as its C counterpart, including the macros _IOFBF,
  109.       _IOLBF, and _IONBF, except that the buffer parameter
  110.       specifies a scalar variable to use as    a buffer.  WARNING: A
  111.       variable used    as a buffer by FileHandle::setvbuf must    not be
  112.       modified in any way until the    FileHandle is closed or    until
  113.       FileHandle::setvbuf is called    again, or memory corruption
  114.       may result!
  115.  
  116.       See the _p_e_r_l_f_u_n_c manpage for complete    descriptions of    each
  117.       of the following supported FileHandle    methods, which are
  118.       just front ends for the corresponding    built-in functions:
  119.  
  120.  
  121.  
  122.  
  123.  
  124.  
  125.  
  126.  
  127.  
  128.  
  129.      Page 2                        (printed 10/23/98)
  130.  
  131.  
  132.  
  133.  
  134.  
  135.  
  136.      FFFFiiiilllleeeeHHHHaaaannnnddddlllleeee((((3333))))   22223333////JJJJuuuullll////99998888 ((((ppppeeeerrrrllll 5555....000000005555,,,, ppppaaaattttcccchhhh 00002222))))     FFFFiiiilllleeeeHHHHaaaannnnddddlllleeee((((3333))))
  137.  
  138.  
  139.  
  140.           close
  141.           fileno
  142.           getc
  143.           gets
  144.           eof
  145.           clearerr
  146.           seek
  147.           tell
  148.  
  149.       See the _p_e_r_l_v_a_r manpage for complete descriptions of each of
  150.       the following    supported FileHandle methods:
  151.  
  152.           autoflush
  153.           output_field_separator
  154.           output_record_separator
  155.           input_record_separator
  156.           input_line_number
  157.           format_page_number
  158.           format_lines_per_page
  159.           format_lines_left
  160.           format_name
  161.           format_top_name
  162.           format_line_break_characters
  163.           format_formfeed
  164.  
  165.       Furthermore, for doing normal    I/O you    might need these:
  166.  
  167.       $fh->print
  168.            See the print entry in the _p_e_r_l_f_u_n_c manpage.
  169.  
  170.       $fh->printf
  171.            See the printf entry in the _p_e_r_l_f_u_n_c manpage.
  172.  
  173.       $fh->getline
  174.            This works like <$fh> described in the section on _I/_O
  175.            _O_p_e_r_a_t_o_r_s in the    _p_e_r_l_o_p manpage except that it's    more
  176.            readable    and can    be safely called in an array context
  177.            but still returns just one line.
  178.  
  179.       $fh->getlines
  180.            This works like <$fh> when called in an array context
  181.            to read all the remaining lines in a file, except that
  182.            it's more readable.  It will also _c_r_o_a_k() if
  183.            accidentally called in a    scalar context.
  184.  
  185.       There    are many other functions available since FileHandle is
  186.       descended from IO::File, IO::Seekable, and IO::Handle.
  187.       Please see those respective pages for    documentation on more
  188.       functions.
  189.  
  190.      SSSSEEEEEEEE AAAALLLLSSSSOOOO
  191.       The IIIIOOOO extension, the    _p_e_r_l_f_u_n_c manpage, the section on _I/_O
  192.  
  193.  
  194.  
  195.      Page 3                        (printed 10/23/98)
  196.  
  197.  
  198.  
  199.  
  200.  
  201.  
  202.      FFFFiiiilllleeeeHHHHaaaannnnddddlllleeee((((3333))))   22223333////JJJJuuuullll////99998888 ((((ppppeeeerrrrllll 5555....000000005555,,,, ppppaaaattttcccchhhh 00002222))))     FFFFiiiilllleeeeHHHHaaaannnnddddlllleeee((((3333))))
  203.  
  204.  
  205.  
  206.       _O_p_e_r_a_t_o_r_s in the _p_e_r_l_o_p manpage.
  207.  
  208.  
  209.  
  210.  
  211.  
  212.  
  213.  
  214.  
  215.  
  216.  
  217.  
  218.  
  219.  
  220.  
  221.  
  222.  
  223.  
  224.  
  225.  
  226.  
  227.  
  228.  
  229.  
  230.  
  231.  
  232.  
  233.  
  234.  
  235.  
  236.  
  237.  
  238.  
  239.  
  240.  
  241.  
  242.  
  243.  
  244.  
  245.  
  246.  
  247.  
  248.  
  249.  
  250.  
  251.  
  252.  
  253.  
  254.  
  255.  
  256.  
  257.  
  258.  
  259.  
  260.  
  261.      Page 4                        (printed 10/23/98)
  262.  
  263.  
  264.  
  265.